package br.atribuicoes.professor.producaoAcademica

import br.academia.Professor

class EventosController {

	def scaffold = Eventos

	def save = {
		def eventosInstance = new Eventos(params)

		Professor professor = Professor.findByUsername(session.user)
		if (professor){

			if (eventosInstance.save(flush: true)) {

				ProducaoAcademica producaoAcademica = new ProducaoAcademica()
				producaoAcademica.eventos = eventosInstance
				producaoAcademica.dataCadastro = new Date()
				producaoAcademica.save(flush: true)
				professor.addToProducoesAcademica(producaoAcademica)
				flash.message = "${message(code: 'default.created.message', args: [message(code: 'Eventos.label', default: 'Eventos'), eventosInstance.id])}"
				redirect(action: "show", id: eventosInstance.id)
			}else {
				flash.message("ERRO AO CRIAR EVENTO")
				render(view: "create", model: [eventosInstance: eventosInstance])
			}
		}
		else {
			flash.message("Professor Invalido no Sistema!")
			render(view: "create", model: [eventosInstance: eventosInstance])
		}
	}
}
